package com.zyr.controller;

import com.zyr.model.User;
import com.zyr.domain.vo.LoginVo;
import com.zyr.model.Result;
import com.zyr.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张雨润
 * @date 2024/7/26 下午4:02
 * @Description
 */
@Slf4j
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Result<T> login(@RequestBody LoginVo loginVo) {
        return userService.login(loginVo);
    }

    @PostMapping("/logout")
    public Result<T> logout(HttpServletRequest request) {
        return userService.logout(request);
    }
    @GetMapping("/list")
    @PreAuthorize("hasAuthority('user:page')")
    public Result<List<User>> list() {
        return Result.success(userService.list());
    }
}
